package com.dyp.global_exception_handler.model;


import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.servlet.http.HttpServletRequest;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

@Schema(description = "Uniform error")
public class ErrorResponse {

	@Schema(description = "Api address, such as /closerTV/epg/tvservice/list", requiredMode = REQUIRED, example = "admin")
	private String uri;
	
	@Schema(requiredMode = REQUIRED, description = "Which kind of method do you invoke, such as GET/PUT/POST/DELETE")
	private String method;
	
	@Schema(requiredMode = REQUIRED, description = "Custom error code, such as 499 mean unknow error")
	private Integer errorCode;
	
	@Schema(requiredMode = REQUIRED, description = "error detial info")
	private String errorMessage;
	
	@Schema(requiredMode = NOT_REQUIRED, description = "other info, commonly using for error description")
	private String moreInfo;
	
	public ErrorResponse(){}
	
	public ErrorResponse(String uri, String method, Integer errorCode, String errorMessage, String moreInfo){
		this.uri = uri;
		this.method = method;
		this.errorCode = errorCode;
		this.errorMessage = errorMessage;
		this.moreInfo = moreInfo;
	}
	
	public ErrorResponse(HttpServletRequest request, Integer errorCode, String errorMessage, String moreInfo){
		this.uri = request.getRequestURI();
		this.method = request.getMethod();
		this.errorCode = errorCode;
		this.errorMessage = errorMessage;
		this.moreInfo = moreInfo;
	}
	
	public String getUri() {
		return uri;
	}
	
	public void setUri(String uri) {
		this.uri = uri;
	}

	public String getMethod() {
		return method;
	}
	
	public void setMethod(String method) {
		this.method = method;
	}

	public Integer getErrorCode() {
		return errorCode;
	}
	
	public void setErrorCode(Integer errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMessage() {
		return errorMessage;
	}
	
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	
	public String getMoreInfo() {
		return moreInfo;
	}
	
	public void setMoreInfo(String moreInfo) {
		this.moreInfo = moreInfo;
	}

	@Override
	public String toString() {
		return "Error{" +
				"uri='" + uri + '\'' +
				", method='" + method + '\'' +
				", errorCode=" + errorCode +
				", errorMessage='" + errorMessage + '\'' +
				", moreInfo='" + moreInfo + '\'' +
				'}';
	}
}